package com.xh.bussiness.resource.controller;

import com.xh.bussiness.resource.bean.request.MaterialCourseIndexRequest;
import com.xh.bussiness.resource.service.IMaterialCourseIndexService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/admin/materialCourseIndex")
public class MaterialCourseIndexController extends BaseController {

    @Autowired
    private IMaterialCourseIndexService materialCourseIndexService;

    @PostMapping("/query")
    @ApiOperation(value="查询课次资料", notes = "查询课次资料")
    public AjaxResult queryByPage(@RequestBody MaterialCourseIndexRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"",materialCourseIndexService.query(bean));
    }

    @PostMapping("/add")
    @ApiOperation(value="添加课次资料", notes = "添加课次资料")
    public AjaxResult add(@RequestBody List<MaterialCourseIndexRequest> bean){
        if(CollectionUtils.isEmpty(bean)){
            return new AjaxResult(AjaxResultConstant.Result.ERROR,"参数错误！");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"添加成功",materialCourseIndexService.add(bean));
    }


    @PostMapping("/delete")
    @ApiOperation(value="删除课次资料", notes = "删除课次资料")
    public AjaxResult delete(@RequestBody MaterialCourseIndexRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"删除成功",materialCourseIndexService.delete(bean));
    }

    @RequestMapping("/queryMaterialByCourseIndex")
    @ApiOperation(value="查询课次的资料", notes = "查询课次的资料")
    public AjaxResult queryMaterialByCourseIndex(@RequestBody MaterialCourseIndexRequest bean){
        if(StringUtils.isEmpty(bean.getCourseIndexId())){
            return new AjaxResult(AjaxResultConstant.Result.ERROR,"参数错误！");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,materialCourseIndexService.queryMaterialByCourseIndex(bean));
    }

    @RequestMapping("/queryMaterialCountByCourseIndex")
    @ApiOperation(value="查询课次的资料数", notes = "查询课次的资料")
    public AjaxResult queryMaterialCountByCourseIndex(@RequestBody MaterialCourseIndexRequest bean){
        if(StringUtils.isEmpty(bean.getCourseIndexId())){
            return new AjaxResult(AjaxResultConstant.Result.ERROR,"参数错误！");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,materialCourseIndexService.queryMaterialCountByCourseIndex(bean));
    }

}
